/**
 * 系统用户修改js
 */
var comValidform=null;
var returnStatus=false;
var sysUserUpdate={
	dataCache:null,
	duties:null,
	
	bindChangeDept:function(val){
	},
	
	startEvent:function(){

		//更改职务提交
		comValidform=$(".com-addForm").Validform({

			tiptype:2,

			tipSweep:true,

			beforeSubmit:function(curform){
				var url = "";
				var params = jsUtils.serializeJson($('.com-addForm'));
				params.actUserId = userId;

				if(params.actUserId == null){
					alert("登录超时，请重新登录后再进行操作！");
					return false;
				}

				if(params.recommendCode != undefined && params.recommendCode != null &&  params.recommendCode.length != 11 && params.recommendCode.length != 0){
					alert("推荐码格式错误，只能为空或11位手机号！");
					return false;
				}

				url = 'mgr/SysUserCtrl/updateSysUserCode';

				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return returnStatus;
			}

		});
	},
	getChannelResource : function() {
		var url = 'mgr/userChannelCtrl/list';
		var params = {
			'curPage' : 0,
			'pageSize' : 9999
		};
		var cb = function(data) {
			if (data.resultCode == 200) {
				var option = '<option value="">请选择</option>';
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					option = option + '<option value="' + singleObj.channelId + '">'
						+ singleObj.name + '</option>';
				}
				$('select[name="channel"]').append(option);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');

	},

	showInfoById:function(){
		var updId=art.dialog.data('updId');  //修改id
		var url = 'mgr/SysUserCtrl/getSysUserById';
		var params ={
				'id':updId
		};
		var cb = function(data){
			if(data.resultCode==200){
				var ret=data.result;
				$('.com-addForm input[name="recommendCode"]').val(ret.recommendCode);
				$('.com-addForm input[name="id"]').val(ret.id);
				$('.com-addForm select[name="channel"]').val(ret.channel);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	init:function(){
		sysUserUpdate.getChannelResource();
		sysUserUpdate.showInfoById();
		sysUserUpdate.startEvent();

	}
}
$(document).ready(function() {
	sysUserUpdate.init();
});

function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}